﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D; // For LinearGradientBrush
/*System.Drawing.Drawing2D.HatchBrush（阴影、前景色和背景色定义的矩形笔刷）
      System.Drawing.Drawing2D.LinearGradientBrush（线性渐变笔刷）
      System.Drawing.Drawing2D.PathGradientBrush（用渐变填充 GraphicsPath 对象的内部的笔刷）
      System.Drawing.TextureBrush（用图像来填充形状的内部的笔刷）*/
using System.Windows.Forms; // For Panel

namespace RobotCleaner
{
    /// <summary>
    /// 污浊区域
    /// </summary>
    public class DirtyArea
    {
        /// <summary>
        /// 污浊区域的颜色
        /// </summary>
        private Color _d_Color = Color.Yellow;
        private Point _dirty;
        private int _d_X;
        private int _d_Y;
        private int _d_Width;
        private int _d_Height;
        /// <summary>
        /// 污浊点 X
        /// </summary>
        public int D_X
        {
            get { return _d_X; }
            set { _d_X = value; }
        }
        /// <summary>
        /// 污浊点 Y
        /// </summary>
        public int D_Y
        {
            get { return _d_Y; }
            set { _d_Y = value; }
        }
        /// <summary>
        /// 污浊点 宽
        /// </summary>
        public int D_Width
        {
            get { return _d_Width; }
            set { _d_Width = value; }
        }
        /// <summary>
        /// 污浊点 高
        /// </summary>
        public int D_Height
        {
            get { return _d_Height; }
            set { _d_Height = value; }
        }
        /// <summary>
        /// 污浊点
        /// </summary>
        public Point Dirty
        {
            get { return _dirty; }
            set { _dirty = value; }
        }
        /// <summary>
        /// 污浊区域 构造函数初始化
        /// </summary>
        /// <param name="_p1"></param>
        /// <param name="_p2"></param>
        public DirtyArea(Point _p1,Point _p2)
        {
            _dirty = _p1;
            _d_Width = _p2.X - _p1.X;
            _d_Height = _p2.Y - _p1.Y;
            _d_X = _p1.X;
            _d_Y = _p2.Y;
        }
        /// <summary>
        /// 绘制污浊区域
        /// </summary>
        /// <param name="_p"></param>
        /// <param name="_s"></param>
        /// <param name="panel"></param>
        public void drawDirty(Point _p,Size _s, Panel panel)
        {
            try
            {
                Rectangle rec = new Rectangle(_p.X, _p.Y, _s.Width, _s.Height);
                using (Graphics g = panel.CreateGraphics())
                {
                    g.FillEllipse(new SolidBrush(_d_Color), // LinearGradientBrush
                           rec);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("绘制污浊区域出错："+ex.ToString());
            }
        }
    }
}
